package com.rfid.web.controller.api;


import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.rfid.common.constant.CodeConstants;
import com.rfid.common.core.controller.BaseController;
import com.rfid.common.core.domain.AjaxResult;
import com.rfid.common.core.domain.entity.SysDictData;
import com.rfid.common.core.domain.entity.SysMenu;
import com.rfid.common.core.domain.entity.SysUser;
import com.rfid.common.core.page.TableDataInfo;
import com.rfid.common.enums.ItemInfoEnums;
import com.rfid.common.exception.BusinessException;
import com.rfid.common.exception.RFIDException;
import com.rfid.common.utils.ObjectConversion;
import com.rfid.common.utils.ShiroUtils;
import com.rfid.common.utils.StringUtils;
import com.rfid.framework.web.service.CodeGenerateService;
import com.rfid.system.domain.*;
import com.rfid.system.domain.request.*;
import com.rfid.system.domain.response.*;
import com.rfid.system.service.*;
import com.rfid.system.service.common.DictRfidService;
import com.rfid.system.service.common.RfidConfigService;
import net.sf.ehcache.util.ProductInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/api/")
public class ApiController extends BaseController {

    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private ITIteminfoService tIteminfoService;

    @Autowired
    private ITProductInfoService iTProductInfoService;

    @Autowired
    private RfidConfigService rfidConfigService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private ISysConfigService iSysConfigService;

    @Autowired
    private ITOrderTotalService iTOrderTotalService;

    @Autowired
    private DictRfidService dictRfidService;

    @Autowired
    private ITRfidDataDetailService tRfidDataDetailService;

    @Autowired
    private ITRfidAuditTotalService iTRfidAuditTotalService;

    @Autowired
    private ITRfidAuditService itRfidAuditService;

    @Autowired
    private CodeGenerateService codeGenerateService;

    @Autowired
    private ObjectConversion objectConversion;



    /**
     * 获取客户信息
     * @return
     */
    @RequiresPermissions("api:customer:info")
    @GetMapping("/customer/info")
    @ResponseBody
    public AjaxResult getCustomerInfo(){
        logger.info("======手持机端开始获取客户信息111=======");
        return AjaxResult.success();
    }

    /**
     * 获取用户菜单
     * @return
     */
    @GetMapping("/customer/menus")
    @ResponseBody
    public AjaxResult getMenus(){
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        return  AjaxResult.success(menus);
    }


    /**
     * 查询成品列表
     */
    @RequiresPermissions("api:equipment:productLink")
    @PostMapping("/rfid/iteminfo")
    @ResponseBody
    public TableDataInfo list(TItemInfoRequestVO vo, HttpServletRequest request) {
        startPage();
        if(StringUtils.isEmpty(vo.getMAC())){
            throw new RFIDException("MAC地址不能为空");
        }
        if(StringUtils.isEmpty(vo.getLongitudeLatitude())){
            throw new RFIDException("经纬度不能为空");
        }else{
            if(!vo.getLongitudeLatitude().contains(",")){
                throw new RFIDException("经纬度格式不正确");
            }
        }
        if(StringUtils.isEmpty(vo.getIp())){
            throw new RFIDException("ip不能为空");
        }
        TItemInfo tIteminfo=new TItemInfo();
        tIteminfo.setItemNo(vo.getItemNo());
        List<TItemInfo> list = tIteminfoService.selectTIteminfoList(tIteminfo);
        List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();
        String itemCodeLength =rfidConfigService.getKey("ITEM_CODE_LENGTH");
        if(itemCodeLength==null){
            throw new BusinessException("成品表-序列号长度未配置");
        }
        if(CollectionUtils.isNotEmpty(list)){
            list.forEach(info->{
                Map<String,Object> map= Maps.newHashMap();
                String itemNo=info.getItemNo();
                String productNo=itemNo.substring(0,Integer.valueOf(itemCodeLength));
                //查询产品信息
                TProductInfo tProductInfo=new TProductInfo();
                tProductInfo.setProductNo(productNo);
                List<TProductInfo> listProduct=iTProductInfoService.selectTProductInfoList(tProductInfo);
                if(CollectionUtils.isEmpty(listProduct)){
                    throw new RFIDException("成品编号"+itemNo+"没有对应的产品信息");
                }
                tProductInfo=listProduct.get(0);
                map.put("itemNo",info.getItemNo());
                map.put("epc",info.getEpc());
                map.put("productInfoId",info.getProductInfoId());
                map.put("tid",info.getTid());
                map.put("createTime",info.getCreateTime());
                map.put("productName",tProductInfo.getProductName());
                map.put("productType",dictRfidService.getLabel("PRODUCT_TYPE",String.valueOf(tProductInfo.getProductCode())));
                data.add(map);
            });
        }
        return getDataTable(data);
    }

    /**
     * 单品关联RFID标签信息
     */
    @RequiresPermissions("api:equipment:productLink")
    @PostMapping("/rfid/itemlinkrfidinfo")
    @ResponseBody
    public AjaxResult itemLinkRfidInfo(TItemInfoRequestVO vo){
        String longitude="";
        String latitude="";
        if(StringUtils.isEmpty(vo.getMAC())){
            throw new RFIDException("MAC地址不能为空");
        }
        if(StringUtils.isEmpty(vo.getIp())){
            throw new RFIDException("ip不能为空");
        }
        if(StringUtils.isEmpty(vo.getLongitudeLatitude())){
            throw new RFIDException("经纬度不能为空");
        }else{
            if(!vo.getLongitudeLatitude().contains(",")){
                throw new RFIDException("经纬度格式不正确");
            }
            String[] longitude_latitude=vo.getLongitudeLatitude().split(",");
            longitude=longitude_latitude[0];
            latitude=longitude_latitude[1];
        }
        if(StringUtils.isEmpty(vo.getItemNo())){
            throw new RFIDException("单品号不能为空");
        }
        if(StringUtils.isEmpty(vo.getEPC())){
            throw new RFIDException("EPC不能为空");
        }
        if(StringUtils.isEmpty(vo.getTID())){
            throw new RFIDException("TID不能为空");
        }
        TItemInfo tIteminfo=new TItemInfo();
        tIteminfo.setItemNo(vo.getItemNo());
        List<TItemInfo> list=tIteminfoService.selectTIteminfoList(tIteminfo);
        if(CollectionUtils.isEmpty(list)){
            throw new RFIDException("单品号对应的单品不存在");
        }else{
            tIteminfo=list.get(0);
            if(StringUtils.isNotEmpty(tIteminfo.getEpc())){
                throw new RFIDException("该成品已绑定EPC");
            }
        }
        tIteminfo=new TItemInfo();
        tIteminfo.setEpc(vo.getEPC());
        List<TItemInfo> listEpc=tIteminfoService.selectTIteminfoList(tIteminfo);
        if(!CollectionUtils.isEmpty(listEpc)){
            throw new RFIDException("EPC已绑定,请勿重复绑定");
        }
        //查询经度的参数值
        String accuracy=iSysConfigService.selectConfigByKey("ACCURACY_CONFIG");
        String longitudeLatitude=this.getLongitudeLatitude(Integer.valueOf(accuracy),longitude,latitude);
        TItemInfo itemInfo=list.get(0);
        itemInfo.setEpc(vo.getEPC());
        itemInfo.setTid(vo.getTID());
        itemInfo.setLocationType(vo.getLocationType());
        itemInfo.setLongitudeLatitude(longitudeLatitude);
        itemInfo.setIp(vo.getIp());
        itemInfo.setUpdateBy(ShiroUtils.getLoginName());
        itemInfo.setUpdateTime(new Date());
        tIteminfoService.updateTIteminfo(itemInfo);
        return AjaxResult.success("操作成功");
    }

    /**
     * @Author fangchen
     * @Description //通过出货单号（二维码）获取出货单信息及单品信息
     * @Date 9:39 2020/12/25
     * @Param [orderNo] orderNo单据号
     * @return com.rfid.common.core.domain.AjaxResult
     **/
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getOrderAndItem")
    @ResponseBody
    public AjaxResult getOrderAndItem(String orderNo){
        if(StringUtils.isEmpty(orderNo)){
            throw new RFIDException("单据号不能为空");
        }
        OrderInfoResponseVO orderInfoResponseVO=iTOrderTotalService.selectOrderInfo(orderNo);
        if(orderInfoResponseVO==null){
            throw new RFIDException("出货单信息不存在");
        }
        List<Map<String,Object>> list=iTOrderTotalService.getProductInfo(orderNo);
        List<SysDictData> dataList=dictTypeService.selectDictDataByType(CodeConstants.PRODUCT_TYPE);
        if(CollectionUtils.isEmpty(dataList)){
            throw new RFIDException("产品类型数据异常");
        }
        if(CollectionUtils.isNotEmpty(list)){
            list.forEach(map->{
                map.put("productType",dictRfidService.getLabel("PRODUCT_TYPE",String.valueOf(map.get("productCode"))));
                map.remove("productCode");
            });
        }else{
            list=new ArrayList<>();
        };
        TItemInfo tItemInfo=new TItemInfo();
        tItemInfo.setDocumentNo(orderNo);
        List<TItemInfoAndProduct> tItemInfoAndProducts=tIteminfoService.selectTitemInfoAndProducts(tItemInfo);
        if(CollectionUtils.isNotEmpty(tItemInfoAndProducts)){
            orderInfoResponseVO.settItemInfoAndProducts(tItemInfoAndProducts);
        }else{
            tItemInfoAndProducts=new ArrayList<>();
            orderInfoResponseVO.settItemInfoAndProducts(tItemInfoAndProducts);
        }
        orderInfoResponseVO.setProductInfos(list);
        return AjaxResult.success(orderInfoResponseVO);
    }

    /**
     * @Author fangchen
     * @Description //单据关联单品信息
     * @Date 11:18 2020/12/26
     * @Param []
     * @return com.rfid.common.core.domain.AjaxResult
     **/
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getOrderLinkItem")
    @ResponseBody
    @Transactional
    public AjaxResult getOrderLinkItem(OrderLinkItemRequestVO vo){
        if(StringUtils.isEmpty(vo.getMAC())){
            throw new RFIDException("MAC地址不能为空");
        }
        if(StringUtils.isEmpty(vo.getLocationType())){
            throw new RFIDException("位置类别不能为空");
        }
        if(StringUtils.isEmpty(vo.getDocumentNo())){
            throw new RFIDException("单据号不能为空");
        }
        if(StringUtils.isEmpty(vo.getDocumentNo())){
            throw new RFIDException("单据号不能为空");
        }
        if(StringUtils.isEmpty(vo.getLongitudeLatitude())){
            throw new RFIDException("经纬度不能为空");
        }else{
            if(!vo.getLongitudeLatitude().contains(",")){
                throw new RFIDException("经纬度格式不正确");
            }
        }
        if(StringUtils.isEmpty(vo.getEPCS())){
            throw new RFIDException("EPCS不能为空");
        }else{
            if(!vo.getLongitudeLatitude().contains(",")){
                throw new RFIDException("EPCS格式不正确");
            }
        }
        if(StringUtils.isEmpty(vo.getIp())){
            throw new RFIDException("IP地址不能为空");
        }
        String[] epcs=vo.getEPCS().split(",");
        String[]  longitude_latitude=vo.getLongitudeLatitude().split(",");
        String longitude=longitude_latitude[0];
        String latitude=longitude_latitude[1];
        String ip=vo.getIp();
        //查询经度的参数值
        String accuracy=iSysConfigService.selectConfigByKey("ACCURACY_CONFIG");
        String longitudeLatitude=this.getLongitudeLatitude(Integer.valueOf(accuracy),longitude,latitude);
        String addressType=vo.getLocationType();
        String documentNo=vo.getDocumentNo();
        String createBy=ShiroUtils.getLoginName();
        for(int i=0;i<epcs.length;i++){
            //新增一条rfid明细数据
            TRfidDataDetail tRfidDataDetail=new TRfidDataDetail();
            tRfidDataDetail.setEPC(epcs[i]);
            tRfidDataDetail.setAddressType(addressType);
            tRfidDataDetail.setDocumentNo(documentNo);
            tRfidDataDetail.setLongitudeLatitude(longitudeLatitude);
            tRfidDataDetail.setFuncId(133L);
            tRfidDataDetail.setCreateBy(createBy);
            tRfidDataDetail.setCreateTime(new Date());
            tRfidDataDetailService.insertTRfidDataDetail(tRfidDataDetail);
            //通过epc更新成品表
            TItemInfo tItemInfo=new TItemInfo();
            tItemInfo.setEpc(epcs[i]);
            List<TItemInfo> itemInfos=tIteminfoService.selectTIteminfoList(tItemInfo);
            if(CollectionUtils.isEmpty(itemInfos)){
                throw new RFIDException("epc"+epcs[i]+"对应的成品信息不存在");
            }
            TItemInfo  itemInfo=itemInfos.get(0);
            itemInfo.setDocumentNo(documentNo);
            itemInfo.setLocationType(addressType);
            itemInfo.setLongitudeLatitude(longitudeLatitude);
            itemInfo.setIp(ip);
            itemInfo.setCreateTime(new Date());
            tIteminfoService.updateTIteminfo(itemInfo);
        }
        return  AjaxResult.success();
    };

    /**
     * @Author fangchen
     * @Description //通过RFID编号获取单品信息
     * @Date 17:20 2020/12/30
     * @Param []
     * @return com.rfid.common.core.domain.AjaxResult
     **/
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getOrderInfos")
    @ResponseBody
    public AjaxResult getOrderInfos(GetOrderInfosVO getOrderInfosVO){
        if(StringUtils.isEmpty(getOrderInfosVO.getEpc())){
            throw new RFIDException("EPC不能为空");
        };
        String[] epc=getOrderInfosVO.getEpc().split(",");
        List<Map<String,Object>> resp= Lists.newLinkedList();
        for(int i=0;i<epc.length;i++){
            getOrderInfosVO=new GetOrderInfosVO();
            getOrderInfosVO.setEpc(epc[i]);
            Map<String,Object> map=tIteminfoService.getOrderInfos(getOrderInfosVO);
            if(map!=null){
                resp.add(map);
            }
        }
        return  AjaxResult.success(resp);
    };

    /**
     * 稽查结果收集
     * @return
     */
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/checkResult")
    @ResponseBody
    @Transactional
    public AjaxResult checkResult(@RequestBody CheckResultRequestVO checkResultRequestVO){
        logger.info("===========开始稽查结果收集======");
        if(CollectionUtils.isEmpty(checkResultRequestVO.getResultVOList())){
            throw new RFIDException("稽查记录不能为空");
        }
        if(StringUtils.isEmpty(checkResultRequestVO.getAddressType())){
            throw new RFIDException("位置类别不能为空");
        }
        if(StringUtils.isEmpty(checkResultRequestVO.getDocumentNo())){
            throw new RFIDException("单据号不能为空");
        }
        if(StringUtils.isEmpty(checkResultRequestVO.getLongitudeLatitude())){
            throw new RFIDException("经纬度值不能为空");
        }else{
            if(!checkResultRequestVO.getLongitudeLatitude().contains(",")){
                throw new RFIDException("经纬度值格式不正确");
            }
        }
        try {
            if(StringUtils.isEmpty(checkResultRequestVO.getIp())){
                throw new RFIDException("IP不能为空");
            }
            //生成一条稽查总表的记录
            TRfidAuditTotal lastData=iTRfidAuditTotalService.getLastData();
            String auditNo="";
            if(lastData!=null){
                auditNo=codeGenerateService.generateCode("CHECK_CODE_RULE",lastData.getAuditNo(),lastData);
            }else{
                auditNo=codeGenerateService.generateCode("CHECK_CODE_RULE","",lastData);
            }
            TRfidAuditTotal tRfidAuditTotal=new TRfidAuditTotal();
            tRfidAuditTotal.setAuditNo(auditNo);
            tRfidAuditTotal.setDocumentNo(checkResultRequestVO.getDocumentNo());
            tRfidAuditTotal.setType(checkResultRequestVO.getType());
            tRfidAuditTotal.setAuditDate(new Date());
            tRfidAuditTotal.setCreateTime(new Date());
            tRfidAuditTotal.setCreateBy(ShiroUtils.getLoginName());
            iTRfidAuditTotalService.insertTRfidAuditTotal(tRfidAuditTotal);
            //生成一条稽查明细数据
            String[]  longitude_latitude=checkResultRequestVO.getLongitudeLatitude().split(",");
            String longitude=longitude_latitude[0];
            String latitude=longitude_latitude[1];
            String accuracy=iSysConfigService.selectConfigByKey("ACCURACY_CONFIG");
            String longitudeLatitude=this.getLongitudeLatitude(Integer.valueOf(accuracy),longitude,latitude);
            List<ResultVO> resultVOList=checkResultRequestVO.getResultVOList();
/*            if(resultVOList.size()<4){
                throw new RFIDException("稽查结果收集请求参数resultVOList数组大小为"+resultVOList.size());
            }*/
            for(ResultVO resultVO:resultVOList){
                //通过EPC查询单品号和产品编号
                TItemInfo tItemInfo=new TItemInfo();
                tItemInfo.setEpc(resultVO.getEpc());
                List<TItemInfo> tItemInfos=tIteminfoService.selectTIteminfoList(tItemInfo);
                if(CollectionUtils.isEmpty(tItemInfos)){
                    throw new RFIDException("EPC"+resultVO.getEpc()+"对应的成品不存在");
                }
                tItemInfo=tItemInfos.get(0);
                TRfidAudit tRfidAudit=new TRfidAudit();
                tRfidAudit.setTid(resultVO.getTid());
                tRfidAudit.setAddressType(checkResultRequestVO.getAddressType());
                tRfidAudit.setAuditNo(auditNo);
                tRfidAudit.setItemNo(tItemInfo.getItemNo());
                tRfidAudit.setProductNo(tItemInfo.getField());
                tRfidAudit.setDocumentNo(checkResultRequestVO.getDocumentNo());
                tRfidAudit.setEpc(resultVO.getEpc());
                tRfidAudit.setIsNormal(resultVO.getResult());
                tRfidAudit.setLongitudeLatitude(longitudeLatitude);
                tRfidAudit.setCreateBy(ShiroUtils.getLoginName());
                tRfidAudit.setCreateTime(new Date());
                itRfidAuditService.insertTRfidAudit(tRfidAudit);
                //生成一条RFID数据明细表
                TRfidDataDetail tRfidDataDetail=new TRfidDataDetail();
                tRfidDataDetail.setItemNo(tItemInfo.getItemNo());
                tRfidDataDetail.setDocumentNo(checkResultRequestVO.getDocumentNo());
                tRfidDataDetail.setProductId(tItemInfo.getProductInfoId());
                tRfidDataDetail.setField(tItemInfo.getField());//产品编号
                tRfidDataDetail.setFuncId(135L);
                tRfidDataDetail.setEPC(resultVO.getEpc());
                tRfidDataDetail.setAddressType(checkResultRequestVO.getAddressType());
                tRfidDataDetail.setLongitudeLatitude(longitudeLatitude);
                tRfidDataDetail.setCreateBy(ShiroUtils.getLoginName());
                tRfidDataDetail.setCreateTime(new Date());
                tRfidDataDetailService.insertTRfidDataDetail(tRfidDataDetail);
            }
        }catch (Exception e){
            logger.error("稽查结果异常",e);
            e.printStackTrace();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    /**
     * @Author fangchen
     * @Description //通过单品RFID编码获取单据信息
     * @Date 18:56 2021/1/18
     * @Param []
     * @return com.rfid.common.core.domain.AjaxResult
     **/
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getOrderInfo")
    @ResponseBody
    public AjaxResult getOrderInfo(String epc){
        if(StringUtils.isEmpty(epc)){
            throw new RFIDException("epc不能为空");
        }
        List<TItemInfoResponseVO> tItemInfoAndProducts=tIteminfoService.getItemByEpc(epc);
        if(CollectionUtils.isEmpty(tItemInfoAndProducts)){
            tItemInfoAndProducts=new ArrayList<>();
        }
        List<DocumentInfoResponseVO> documentInfoResponseVOList=tIteminfoService.selectByEpc(epc);
        if(CollectionUtils.isEmpty(documentInfoResponseVOList)||documentInfoResponseVOList.get(0)==null){
            throw new RFIDException("epc对应单据信息不存在");
        }
        Map<String,Object> resp=Maps.newHashMap();
        resp.put("documentInfoResponseVOList",documentInfoResponseVOList);
        resp.put("tItemInfoVOList",tItemInfoAndProducts);
        return AjaxResult.success(resp);
    };

    /**
     * 通过单品RFID编码获取物流信息
     * @return
     */
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getLogisticsInfo")
    @ResponseBody
    public AjaxResult getLogisticsInfo(String epc){
        if(StringUtils.isEmpty(epc)){
            throw new RFIDException("epc不能为空");
        }
        TRfidDataDetail tRfidDataDetail=new TRfidDataDetail();
        tRfidDataDetail.setEPC(epc);
        List<TRfidDataDetail> tRfidDataDetailList= tRfidDataDetailService.selectTRfidDataDetailList(tRfidDataDetail);
        List<TRfidDataDetailResponseVO> list=objectConversion.copy(tRfidDataDetailList,TRfidDataDetailResponseVO.class);
        if(CollectionUtils.isEmpty(list)){
            throw new RFIDException("epc对应单据信息不存在");
        }
        return AjaxResult.success(list);
    };

    /**
     * 通过单品号,获取单品对应的RFID数据明细信息
     * @return
     */
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getDataDetail")
    @ResponseBody
    public AjaxResult getDataDetail(String itemNo){
        if(StringUtils.isEmpty(itemNo)){
            throw new RFIDException("单品号不能为空");
        }
        TRfidDataDetail tRfidDataDetail=new TRfidDataDetail();
        tRfidDataDetail.setItemNo(itemNo);
        TRfidDataDetailByItemNOResponseVO tRfidDataDetailByItemNOResponseVO= tRfidDataDetailService.selectTRfidDataDetailByItemNolList(tRfidDataDetail);
        List<RfidDetailVO> list= tRfidDataDetailByItemNOResponseVO.getRfidDetailVOList();
        list.stream().forEach(dto->{
            // map.put("productType",dictRfidService.getLabel("PRODUCT_TYPE",String.valueOf(map.get("productCode"))));
            dto.setFuncName(dictRfidService.getLabelByCode("RFID_FUNCTION",dto.getFuncId()+""));
        });
        return AjaxResult.success(tRfidDataDetailByItemNOResponseVO);
    }

    /**
     * 通过手机传输的EPC与TID判断单品查询情况
     * @return
     */
    @RequiresPermissions("api:equipment:getOrderAndItem")
    @PostMapping("/rfid/getItemInfo")
    @ResponseBody
    public Map<String,Object> getItemInfo(String EPC,String TID){
        Map<String,Object> resp=Maps.newLinkedHashMap();
        if(StringUtils.isEmpty(EPC)){
            throw new RFIDException("EPC不能为空");
        }
        if(StringUtils.isEmpty(TID)){
            throw new RFIDException("TID不能为空");
        }
        //都不相同
        TItemInfo tItemInfo=new TItemInfo();
        tItemInfo.setTid(TID);
        List<TItemInfo> itemInfostid=tIteminfoService.selectTIteminfoList(tItemInfo);
        tItemInfo=new TItemInfo();
        tItemInfo.setEpc(EPC);
        List<TItemInfo> itemInfosepc=tIteminfoService.selectTIteminfoList(tItemInfo);
        if(CollectionUtils.isEmpty(itemInfostid)&&CollectionUtils.isEmpty(itemInfosepc)){
            resp.put("code", ItemInfoEnums.NOT_COMPANY_PRODUCT.getCode());
            resp.put("message", ItemInfoEnums.NOT_COMPANY_PRODUCT.getMessage());
            resp.put("itemNo",null);
            resp.put("productName",null);
        }
        //都相同
        tItemInfo=new TItemInfo();
        tItemInfo.setTid(TID);
        tItemInfo.setEpc(EPC);
        List<TItemInfo> itemInfosepctid=tIteminfoService.selectTIteminfoList(tItemInfo);
        if(!CollectionUtils.isEmpty(itemInfosepctid)){
            resp.put("code", ItemInfoEnums.TRUTH_PRODUCT.getCode());
            resp.put("message", ItemInfoEnums.TRUTH_PRODUCT.getMessage());
            tItemInfo=itemInfosepctid.get(0);
            TProductInfo tProductInfo=iTProductInfoService.selectTProductInfoById(Long.valueOf(tItemInfo.getProductInfoId()));
            resp.put("itemNo",tItemInfo.getItemNo());
            if(tProductInfo==null){
                resp.put("productName",null);
            }else{
                resp.put("productName",tProductInfo.getProductName());
            }
        }
        //tid相同 epc不同
        if(CollectionUtils.isNotEmpty(itemInfostid)&&CollectionUtils.isEmpty(itemInfosepc)){
            if(itemInfostid.get(0).getTid().equals(TID)){
                resp.put("code", ItemInfoEnums.UPDATED_PRODUCT.getCode());
                resp.put("message", ItemInfoEnums.UPDATED_PRODUCT.getMessage());
                tItemInfo=itemInfostid.get(0);
                TProductInfo tProductInfo=iTProductInfoService.selectTProductInfoById(Long.valueOf(tItemInfo.getProductInfoId()));
                resp.put("itemNo",tItemInfo.getItemNo());
                if(tProductInfo==null){
                    resp.put("productName",null);
                }else{
                    resp.put("productName",tProductInfo.getProductName());
                }
            }
        }
        //tid不同 epc相同
        if(CollectionUtils.isNotEmpty(itemInfosepc)&&CollectionUtils.isEmpty(itemInfostid)){
            if(itemInfosepc.get(0).getEpc().equals(EPC)){
                resp.put("code", ItemInfoEnums.FALSE_PRODUCT.getCode());
                resp.put("message", ItemInfoEnums.FALSE_PRODUCT.getMessage());
                tItemInfo=itemInfosepc.get(0);
                TProductInfo tProductInfo=iTProductInfoService.selectTProductInfoById(Long.valueOf(tItemInfo.getProductInfoId()));
                resp.put("itemNo",tItemInfo.getItemNo());
                if(tProductInfo==null){
                    resp.put("productName",null);
                }else{
                    resp.put("productName",tProductInfo.getProductName());
                }
            }
        }
        return resp;
    }
}
